<?php
namespace App\Http\Query;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Log;

class SupplierQuery extends Model
{

    // 设置表名NAME="supplier_master";
    // 设置表名
    const TABLE_NAME = "supplier_master";

    protected $table = 'supplier_master';

    protected $primaryKey = 'supplis_id';

    protected $SupplierMaster = self::TABLE_NAME;

    public $timestamps = false;

    public function oneSupplierMaster($data, $arr) // 单条查询
    {
        return $this->where($data, $arr)
            ->get()
            ->toArray();
    }

    public function delSupplierMaster($supplier_id) // 删
    {
        $SupplierMaster = $this->where($supplier_id);
        $sql = 'update supplier_master set delete_flg = 1 where supplier_id=?';
        $param = [
            $supplier_id
        ];
        $delflag = DB::update($sql, $param);
        return $delflag;
    }

    public function updSupplierMaster($data, $list, $arr) // 改
    {
        $SupplierMaster = $this->where($list, '=', $data);
        return $SupplierMaster->update($arr);
    }

    public function addSupplierMaster($data) // 增
    {
        return DB::table('supplier_master')->insert($data);
    }

    public function getSupplierInfoByLoginId($supplier_id)
    {
        $sql = 'select * from supplier_master where  delete_flg = 0 and supplier_id = ?';
        $param = [
            $supplier_id
        ];

        $users = DB::select($sql, $param);
        return $users;
    }

    public function getsupplierid()
    {
        $sql = 'select supplier_id from supplier_master';
        $supplierid = DB::select($sql);
        return $supplierid;
    }

    public function getSupplierMaster()
    {
        $sql = 'select * from supplier_master where delete_flg = 0';

        $corpInfo = DB::select($sql);
        return $corpInfo;
    }

    public function addCsvSupplierMaster($data)
    {
        if (isset($data[0]) && ! empty($data[0])) {
            $sql = 'INSERT INTO  supplier_master (supplier_name, supplier_catelogue, supplier_postcode, supplier_adress, supplier_biru_name, supplier_tel, supplier_fax, supplier_mail, supplier_stuff, stuff_kana, supplier_stuff_telephone, stuff_mail, delete_flg, created_at, updated_at)
                    VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
            $param = $data;
            DB::insert($sql, $param);
        }
    }
}
